package com.lh.lepay.handle;

import com.alibaba.fastjson.JSON;
import com.lh.lepay.utils.ResponseData;
import com.lh.lepay.utils.WebUtils;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author liuzongyi ~ Mr.Liu
 * @week 星期二
 * @address https://github.com/liu17y
 * @since 2024/6/11~~15:59
 * 权限不足处理器
 */
@Component
public class AccessDeniedHandlerImpl implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        ResponseData responseData = new ResponseData(HttpStatus.FORBIDDEN.value(),"权限不足");
        String json = JSON.toJSONString(responseData);
        WebUtils.renderString(response,json);
    }
}
